/**
 * 初始化类别树
 * @returns
 */
function initTree() {
    $$.ajax({
        url: "/rest/IotPointCatalogBusiness/listAllSort",
        suiteCode:"iot",
        async: false,
        data: {},
        success: function (data) {
        	createDeptTree(data);
        }
    });
}

/**
 * 创建类别树
 * @param sourceData
 * @returns
 */
function createDeptTree(sourceData){
	var source = {
        dataType: "json",
        dataFields: [{
            name: "stockName",
            type: "string",
        }, {
            name: "DataSourceID",
            type: "string",
        }, {
            name: 'children',
            type: 'array'
        }, {
            name: 'expanded',
            type: 'bool'
        }],
        hierarchy: {
            root: 'children'
        },
        id: 'DataSourceID',
        localData: sourceData
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    $("#setClassifyTable").jqxTreeGrid({
    	source: dataAdapter,
        width: '100%',
        altRows: true,
        selectionMode: "singleRow",
        height: 380,
        theme: 'bootstrap',
        showToolbar: false,
        enableHover: true,
        columns: [{
            text: "分类",
            align: "center",
            dataField: "stockName",
        }]
    });
}

/**
 * 获取选中数据
 * @returns
 */
function getSelectCatalogData(){
    var selection = $("#setClassifyTable").jqxTreeGrid('getSelection');
    var len = selection.length;
    if(len == 0){
        //未选中数据提示框
        layer.msg('请选择数据',  {time:2000});
        return false;
    }else{
        var rows= $("#setClassifyTable").jqxTreeGrid('getSelection');
        return rows[0];
    }
}

$(function () {
	initTree();
});




